#import <Foundation/Foundation.h>

/*
 Stock is used for storing the names of each stock by id, 
 and also as element in Order.
 */
@interface Stock : NSObject {
	long sid;
	NSString * sname;
	long qty;
	double price;
}
@property long sid;
@property long qty;
@property double price;
@property (nonatomic,retain) NSString * sname;
-(id) sid:(long)stockId sname:(NSString *) stockName;
-(void) updateStockName;
@end

/*
 Used for organizing a single Order per customer.
 Cusomer id is equivalent to the addres book id.
 */
@interface Order : NSObject {
	long oid;
	long date;
	long shipdate;
	double ototal;
	long ocustomerid;
	NSString * ocustomer;
	NSMutableArray * stocks;
	
}
@property long oid;
@property long shipdate;
@property long odate;
@property long ocustomerid;
@property double ototal;
@property (nonatomic,retain) NSString * ocustomer;

-(bool) save;
-(void) clear;
-(void) addStock:(Stock*)stock;
-(NSArray*) getStocks;
-(long) getStocksCount;
-(Stock*) getStock: (int)row;

-(void) updateTotalAndClear;
-(long*) shipdatePointer;

-(void) reload;
@end

/*
 Used for all business logic in the application.
 A singletom static implementation.
 */
@interface HedronCore : NSObject {}
+ (void)load;
+ (void)initialize;
+ (id)new;
+ (id)allocWithZone:(NSZone *)zone;
+ (id)alloc;

// static messages
+(void) init;
+(void) done;

+(NSString*)dateFormat:(long) date;
+(long) dateFlat:(long) date;

// core implementation
+(void) newStock:(NSString *) stockName;
+(void) updateStock:(long)stockId name:(NSString *) stockName;
+(NSArray*) getStocks;
+(NSArray*) getStocksIndex;
+(long) getStockOffset: (long) ix;
+(void)releaseStocks;

+(Order*) getContextOrder;
+(Order*) getCurrentEditableOrder;
+(void) setCurrentEditableOrder: (Order*)order;
+(bool) deleteOrder: (Order*)order;

+(void) releaseReports;
+(NSArray*) getReportSocks;
+(NSString*) getReportStocksHeader:(int) i;
+(NSArray*) getReportOrders;
+(NSString*) getReportOrdersHeader:(int) i;

+(BOOL)startHTTP;
+(BOOL)stopHTTP;
+(BOOL)isHTTPStarted;
+(NSString *)HTTPMessage;

@end


